import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
      vue(),
    AutoImport({
      imports: [
        'vue',
        {
          'naive-ui': [
            'useDialog',
            'useMessage',
            'useNotification',
            'useLoadingBar'
          ]  //自动导入 naive-ui 中用于全局交互 API 函数
        }
      ]
    }),
    Components({
      resolvers: [NaiveUiResolver()] //自动按需导入并注册 naive-ui 的可视化组件
    })
  ],
  resolve: {  // 路径别名
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  server: {  // 代理（跨域）
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:8081',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})
